/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-1-15 上午11:57 Created by lyyang
 */
package com.jade.bss.business.activity.impl;

import java.util.List;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.jade.bss.business.activity.Activity;
import com.jade.bss.business.activity.ActivityDao;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.criterion.sql.SqlUtils;
import com.jade.framework.base.util.PagingList;

/**
 * 活动dao,jpa实现
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-1-15 上午11:57
 */
@Named ("bss_activityDao")
public class JpaActivityDao implements ActivityDao
{
    @PersistenceContext (unitName = "default")
    protected EntityManager entityManager;

    public void add(Activity activity){
        entityManager.persist(activity);
    }

    public void update(Activity activity){
        entityManager.merge(activity);
    }

    public Activity get(long id){
        return entityManager.find(Activity.class,id);
    }

    public void remove(long id){
        Activity activity = get(id);
        if (activity!=null){
            entityManager.remove(activity);
        }
    }


    public List<Activity> list( Criteria criteria)
    {
        String sql = "SELECT entity FROM Activity entity";
        return SqlUtils.sqlQuery(sql, entityManager, criteria);
    }

    public PagingList<Activity> query(Criteria criteria)
    {
        String sql = "SELECT entity FROM Activity entity";
        return SqlUtils.sqlQuery(sql, entityManager, criteria);
    }
}
